import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { NamesOperatorRecordServiceApi,
NamesOperatorRecordService_listResult,
NamesOperatorRecordService_listVariables,
NamesOperatorRecordService_totalCountResult,
NamesOperatorRecordService_searchResult,
NamesOperatorRecordService_searchVariables,
NamesOperatorRecordService_loadAllResult,
NamesOperatorRecordService_getByIdResult,
NamesOperatorRecordService_getByIdVariables,
NamesOperatorRecordService_addRecordResult,
NamesOperatorRecordService_addRecordVariables,
NamesOperatorRecordService_saveResult,
NamesOperatorRecordService_saveVariables,
NamesOperatorRecordService_removeByIdResult,
NamesOperatorRecordService_removeByIdVariables,
NamesOperatorRecordService_removeByIdListResult,
NamesOperatorRecordService_removeByIdListVariables,
NamesOperatorRecordResultInfo, NamesOperatorRecordPageInfo,
NamesOperatorRecordConnection,
NamesOperatorRecordPackage,
NamesOperatorRecordOrderBy,
NamesOperatorRecordMutationInfo,
NamesOperatorRecordStringFilter,
NamesOperatorRecordNumberFilter,
NamesOperatorRecordBooleanFilter,
namesOperatorRecordServiceQuery,
namesOperatorRecordServiceMutation,
NamesOperatorRecordServiceQueryOptions,
NamesOperatorRecordStore,
NamesOperatorRecordView,
NamesOperatorRecordInput,
NamesOperatorRecordFilter,
NamesOperatorRecordErrorBody} from '../model/names_operator_record_service.model';

/************************************************************************
 * 资源操作日志
 */
@Injectable({
    providedIn: 'root'
})
export class NamesOperatorRecordService implements NamesOperatorRecordServiceApi {

        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<NamesOperatorRecordService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.listGql=`query nars_namesOperatorRecordService_list($filter: NamesOperatorRecordFilter!,$orderBy: OrderBy){${namesOperatorRecordServiceQuery.namesOperatorRecordService_list}}`;
        this.totalCountGql=`query nars_namesOperatorRecordService_totalCount{${namesOperatorRecordServiceQuery.namesOperatorRecordService_totalCount}}`;
        this.searchGql=`query nars_namesOperatorRecordService_search($first: Int!,$offset: Float!,$filter: NamesOperatorRecordFilter!,$orderBy: OrderBy){${namesOperatorRecordServiceQuery.namesOperatorRecordService_search}}`;
        this.searchObjectRef = apollo.watchQuery<NamesOperatorRecordService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query nars_namesOperatorRecordService_loadAll{${namesOperatorRecordServiceQuery.namesOperatorRecordService_loadAll}}`;
        this.getByIdGql=`query nars_namesOperatorRecordService_getById($id: String!){${namesOperatorRecordServiceQuery.namesOperatorRecordService_getById}}`;
    }
    /**
     * 分页查询
     */
    list(variables: NamesOperatorRecordService_listVariables, options:NamesOperatorRecordServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<NamesOperatorRecordService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:NamesOperatorRecordServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<NamesOperatorRecordService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: NamesOperatorRecordService_searchVariables, options:NamesOperatorRecordServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<NamesOperatorRecordService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:NamesOperatorRecordServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<NamesOperatorRecordService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: NamesOperatorRecordService_getByIdVariables, options:NamesOperatorRecordServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<NamesOperatorRecordService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 添加操作日志
     */
    addRecord(variables: NamesOperatorRecordService_addRecordVariables): Observable<FetchResult<NamesOperatorRecordService_addRecordResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesOperatorRecordService_addRecord($path: String!,$operatorType: String!){${namesOperatorRecordServiceMutation.namesOperatorRecordService_addRecord}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 保存对象
     */
    save(variables: NamesOperatorRecordService_saveVariables): Observable<FetchResult<NamesOperatorRecordService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesOperatorRecordService_save($entity: NamesOperatorRecordInput!){${namesOperatorRecordServiceMutation.namesOperatorRecordService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: NamesOperatorRecordService_removeByIdVariables): Observable<FetchResult<NamesOperatorRecordService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesOperatorRecordService_removeById($id: String!){${namesOperatorRecordServiceMutation.namesOperatorRecordService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: NamesOperatorRecordService_removeByIdListVariables): Observable<FetchResult<NamesOperatorRecordService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesOperatorRecordService_removeByIdList($ids: [String]!){${namesOperatorRecordServiceMutation.namesOperatorRecordService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
